package com.intct.hbase.ddl;

import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

/**
 * @author gufg
 * @since 2025-09-29 09:38
 */
public class DropNamespace {
    public static void main(String[] args) throws IOException {
        // 连接HBase--Connection
        Connection connection = ConnectionFactory.createConnection();

        // 获取Admin实例
        Admin admin = connection.getAdmin();

        try {
            // 删除命名空间名称
            String namespace = "intct85_api";

            // 判断命名空间名称存，则删除
            List<String> namespaces = Arrays.asList(admin.listNamespaces());
            if (namespaces.contains(namespace)) {
                // 删除
                admin.deleteNamespace(namespace);
            }
        } catch (IOException e) {
            System.out.println("删除命名空间异常");
        }
        // 关闭资源
        admin.close();
        connection.close();
    }
}
